var combinationSum = function (candidates, target) {
  let res = []
  const breakFn = (startIndex, path, sum) => {
    if (sum > target) {
      return
    }
    if (sum === target) {
      res.push([...path])
      return
    }
    for (let i = startIndex; i < candidates.length; i++) {
      path.push(candidates[i])
      breakFn(i, path, sum + candidates[i])
      path.pop()
    }
  }
  breakFn(0, [], 0)
  return res
};

let candidates = [2, 3, 5], target = 8

combinationSum(candidates, target)